package practica3as;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Principal extends JApplet {

    private int widthApplet = 500;
    private int heightApplet = 470;
    private JPanel downPanel;
    private JDoubleBufferedPanel jDoubleBufferedPanel;
    private JTextField userIDField;
    private JTextField scoreField;
    private JButton nextButton;
    private JButton finishButton;
    private JLabel userIDLabel;
    private JLabel scoreLabel;

    @Override
    public void init() {
        downPanel = new JPanel();
        downPanel.setSize(new Dimension(widthApplet, 70));
        downPanel.setMaximumSize(new Dimension(widthApplet, 70));
        downPanel.setMinimumSize(new Dimension(widthApplet, 70));
        downPanel.setPreferredSize(new Dimension(widthApplet, 70));
        downPanel.setBackground(Color.LIGHT_GRAY);
        downPanel.setVisible(true);

        jDoubleBufferedPanel = new JDoubleBufferedPanel();
        jDoubleBufferedPanel.setSize(new Dimension(500, 400));
        jDoubleBufferedPanel.setMaximumSize(new Dimension(500, 400));
        jDoubleBufferedPanel.setMinimumSize(new Dimension(500, 400));
        jDoubleBufferedPanel.setPreferredSize(new Dimension(500, 400));
        jDoubleBufferedPanel.setVisible(true);

        userIDField = new JTextField();
        userIDField.setSize(new Dimension(90, 28));
        userIDField.setMaximumSize(new Dimension(90, 28));
        userIDField.setMinimumSize(new Dimension(90, 28));
        userIDField.setPreferredSize(new Dimension(90, 28));
        userIDField.setText("prueba.txt");

        scoreField = new JTextField();
        scoreField.setSize(new Dimension(90, 28));
        scoreField.setMaximumSize(new Dimension(90, 28));
        scoreField.setMinimumSize(new Dimension(90, 28));
        scoreField.setPreferredSize(new Dimension(90, 28));
        scoreField.setEditable(false);
        scoreField.setText("0");

        userIDLabel = new JLabel();
        userIDLabel.setText("ID user");

        scoreLabel = new JLabel();
        scoreLabel.setText("Score");

        nextButton = new JButton();
        finishButton = new JButton();

        this.add(jDoubleBufferedPanel, BorderLayout.CENTER);
        this.add(downPanel, BorderLayout.PAGE_END);

        this.setSize(new Dimension(widthApplet, heightApplet));
        this.setVisible(true);

        nextButton.setText("Next");
        finishButton.setText("Finish");

        getDownPanel().add(userIDLabel);
        getDownPanel().add(userIDField);
        getDownPanel().add(scoreLabel);
        getDownPanel().add(scoreField);
        getDownPanel().add(nextButton);
        getDownPanel().add(finishButton);
    }

    @Override
    public void start() {
        SceneController sceneController = new SceneController(this);

        nextButton.addActionListener(sceneController);
        finishButton.addActionListener(sceneController);
        addMouseListener(sceneController);

        sceneController.execute();
    }

    public JPanel getDownPanel() {
        return downPanel;
    }

    public JDoubleBufferedPanel getjDoubleBufferedPanel() {
        return jDoubleBufferedPanel;
    }

    public JTextField getUserIDField() {
        return userIDField;
    }

    public JTextField getScoreField() {
        return scoreField;
    }
}
